@if "%1"=="" echo off


set path1=.
set waittime=5
set ADB=%~dp0/tools/adb
::set ADB=C:/adb/sunmi_remote_adb_windows/bin/adb
rem **************xiaojun**************


rem ************************************************
rem         get filename
rem ************************************************
%ADB% wait-for-device
%ADB% root
%ADB% wait-for-device
%ADB% remount 1>nul 2>nul
if exist %path1%\androidlog goto getfilename
md %path1%\androidlog

:getfilename
move %path1%\*.zip %path1%\androidlog 1>nul 2>nul

set current_time=%date:~0,-3%-%time:~0,-3%
set current_time=%current_time:/=-%
set current_time=%current_time::=-%
set current_time=%current_time: =%

for /f "delims=" %%i in ('%ADB% shell getprop ro.product.name') do (set "productname=%%i")
for /f "delims=" %%i in ('%ADB% shell getprop ro.version.sunmi_versionname') do (set "versionname=%%i")
for /f "delims=" %%i in ('%ADB% shell getprop ro.version.sunmi_versioncode') do (set "versioncode=%%i")
for /f "delims=" %%i in ('%ADB% shell getprop ro.serialno') do (set "serial=%%i")
for /f "delims=" %%i in ('%ADB% shell getprop ro.build.tracker') do (set "tracker=%%i")

if not "%versionname%"=="" (set log_path=%path1%\%productname%_%serial%_%versionname%_%versioncode%_%current_time%) else (set log_path=%path1%\%tracker%_%serial%_%current_time%)

md %log_path%

rem ************************************************
rem         begin to capture log files
rem ************************************************

echo ***********get logcat ***********************
start "logcat" /min cmd /c "%ADB% logcat -b all  > %log_path%\logcat.txt"
echo=

::echo ***********get events ***********************
::start "events" /min cmd /c "%~dp0/tools/adb logcat -v threadtime -b events > %log_path%\events.txt"
::echo=

::echo ***********get system ***********************
::start "system" /min cmd /c "%~dp0/tools/adb logcat -v threadtime -b system > %log_path%\system.txt"
::echo=

::echo ***********get radio ***********************
::start "radio" /min cmd /c "%~dp0/tools/adb logcat -v threadtime -b radio  > %log_path%\radio.txt"
::echo=

::echo ***********get main ***********************
::start "main" /min cmd /c "%~dp0/tools/adb logcat -v threadtime -b main   > %log_path%\main.txt"
::echo=


echo ***********get global ***********************
start "global" /min cmd /c "%ADB% shell getprop > %log_path%\getprop.txt"
echo=

echo ***********get global ***********************
start "global" /min cmd /c "%ADB% shell settings list global > %log_path%\global.txt"
echo=

echo ***********get system ***********************
start "system" /min cmd /c "%ADB% shell settings list system > %log_path%\system.txt"
echo=

echo ***********get secure ***********************
start "secure" /min cmd /c "%ADB% shell settings list secure > %log_path%\secure.txt"
echo=

echo ***********get dmesg ***********************
start "dmesg" /min cmd /c "%ADB% shell dmesg > %log_path%\dmesg.txt"
echo=

::echo ***********get kmsg ***********************
::start "kmsg" /min cmd /c "%~dp0/tools/adb shell cat /proc/kmsg > %log_path%\kmsg.log"
::echo=

echo ***********get bugreport ***********************
%ADB% bugreport %log_path%
echo=

echo ***********get screen ***********************
del %path1%\screen.png  1>nul 2>nul
del %path1%\screen2.png  1>nul 2>nul
(%ADB% shell screencap -p /storage/emulated/0/screen.png)&&(%ADB% wait-for-device pull /storage/emulated/0/screen.png %log_path%)
(%ADB% shell screencap -d 1 -p /storage/emulated/0/screen2.png)&&(%ADB% wait-for-device pull /storage/emulated/0/screen2.png %log_path%)
echo=

copy /y %log_path%\screen.png %path1%
copy /y %log_path%\screen2.png %path1%
copy /y %log_path%\logcat.txt %path1%

echo ***********get other***********************
%ADB% shell dumpsys > %log_path%\dumpsys.txt
%ADB% pull /data/anr %log_path%  
%ADB% pull /data/tombstones %log_path%  
%ADB% pull /data/system/dropbox %log_path%  
%ADB% pull /data/logs %log_path%
%ADB% pull /sdcard/meigLogs %log_path%
%ADB% pull /sdcard/aging.log %log_path%
%ADB% pull /sdcard/cit.log %log_path% 
%ADB% pull /sdcard/sunmi/Welcome %log_path%
%ADB% pull /sdcard/sunmiMqtt %log_path%
%ADB% pull /sdcard/SunmiPayment %log_path%
echo= 

timeout %waittime%

echo ***********kill progress ***********************
taskkill /f /t /fi "windowtitle eq logcat"  
taskkill /f /t /fi "windowtitle eq global"
taskkill /f /t /fi "windowtitle eq system"
taskkill /f /t /fi "windowtitle eq secure"   
::taskkill /f /t /fi "windowtitle eq events"  
::taskkill /f /t /fi "windowtitle eq system" 
::taskkill /f /t /fi "windowtitle eq radio"  
::taskkill /f /t /fi "windowtitle eq main"  
taskkill /f /t /fi "windowtitle eq dmesg"  
::taskkill /f /t /fi "windowtitle eq kmsg"  
echo=

echo ***********zip log ***********************
%~dp0/tools/7z.exe a %log_path%.zip -r "%log_path%/*"
rd /s /q %log_path%

